<!--************************************************************************************************-->
<!-- < addBookResult.php >                                                                           -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder : Tianjiao Li                                                                          -->
<!-- Stu : 10389129                                                                                 -->
<!-- Date: 2012-12-18                                                                               -->
<!-- Destription : Change the directory of images.                                                  ->
<!-- Modifier : Xiaofen Huang                                                                       -->
<!-- Stu : 10389169                                                                                 -->
<!-- Date: 2013-01-08                                                                               -->
<!-- Destription : 修改页面样式，调整布局                                                 ->
<!-- Basic: User:root                                                                               -->
<!--	    Password:                                                                               -->
<!-- Version : 2.1                                                                                  -->
<!-- LastUpdate : 2013-1-2 17:30 BY Tianjiaoli                                                    -->
<!--************************************************************************************************-->

<!DOCTYPE html>
<?php
	include_once("../manager/LabelManager.php");
	include_once("../manager/BookManager.php");
	include_once("../manager/DescriptionManager.php");
	include_once("../db/Book.php");
	include_once("../db/Label.php");
	include_once("../db/Description.php");
	include_once("header.php");
	//include_once("bottom.php");
?>
<html lang="zh-hk">
	<?php
	
	if( isset($_POST['bookname'])) 
	{
		$bookname = $_POST['bookname'];
		$authorname = $_POST['authorname'];
		$authorbrief = $_POST['authorbrief'];
		$price = $_POST['price'];
		$pages = $_POST['pages'];
		$translator = $_POST['translator'];
		$publishing = $_POST['publishing'];
		$content = $_POST['content'];
		
		/*Edit BY Tianjiao Li AT 2013-1-2 17:18*/
		$labels = $_POST['labels'];
		$tableName = "Labels";
		
		$list_of_labels = explode(" ", $labels);
		//echo $list_of_labels;
		
		foreach ($list_of_labels as $label_content) 
		{
			$labelManager = new LabelManager();
			if(!$labelManager->exist($label_content))
			{
				$array = array('Content'=>$label_content);
				LabelManager::getInstance()->insert($array);
			}
		}
		/*Edit BY Tianjiao Li*/
		
		/*Edit BY Tianjiao Li AT 2012-12-23 17:18*/
		// deal with image
		$_FILES["file"]["name"] = $bookname.".jpg";
		move_uploaded_file($_FILES["file"]["tmp_name"],"../images/Books/" . $_FILES["file"]["name"]);
		
		//============== sql add! img address
		$img_address = "../images/Books/" . $_FILES["file"]["name"];		
		/*Edit BY Tianjiao Li*/

		$array = array('Bookname'=>$bookname, 'Authorname'=>$authorname, 'AuthorBrief'=>$authorbrief, 'UploaderID'=>$_SESSION['currentID'],
						'Translator'=>$translator, 'Publishing'=>$publishing, 'Pages'=>$pages, 'Price'=>$price, 'ContentBrief'=>$content);
		
		BookManager::getInstance()->insert($array);
		
		/*Edit BY Tianjiao Li AT 2013-1-2 17:18*/
		foreach ($list_of_labels as $label_content) 
		{
			$array = array('content'=>$label_content, 'Bookname'=>$bookname);
			DescriptionManager::getInstance()->insert($array);
		}
		/*Edit BY Tianjiao Li*/
		
		$_SESSION['currentBook'] = $bookname;
		echo "sucess";
	}
	else
		echo "fail";

	
	?>
	
	<head>
		<title>TINY bOOk</title>
		<meta http-equiv="content-type" content="text/html;charset=UTF-8">
		<meta name="contentType" value="text/html  charset=GBK">
		<link rel="stylesheet" type="text/css" href="../css/result.css"/>
		<link rel="shortcut icon" href="images/shortcut.jpg"/>
		<meta http-equiv="refresh" content="1; url=bookPage.php?book_name=<?=$bookname?>">
	</head>	
		
	<body>
		<div id="result">
			<p>已成功上传书籍，跳转到书籍页面</p>
		</div>
	</body>
</html>